home *** CD-ROM | disk | FTP | other *** search
- /*
- █████████████████████████████████████████████████████████████████████████████
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ KNOW-HOW.SLANG ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- █████████████████████████████████████████████████████████████████████████████
-
- This text contain complete description of KNOW_HOW.SLANG 5.0x, the
- product in the 5th version of library. It provide the following features:
- a. BASIC-like language which could be used for calculators, spreadsheets,
- or as a language of the integrated package.
- b. Slang class child classes could have additional functions and
- work with functions of concrete program.
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- Example:
- Additional (and very powerfull) features are available if KNOW-HOW.SLANG
- is used together with KNOW-HOW.GRAPHICS.
- SLANG is BASIC-like language, designed as CPP class. Its child classes could
- have additional operators, so KNOW-HOW.SLANG.GRAPHICS is the BASIC with
- access to drawing tools of current product. It provide to user the
- possibility to load graphical resourses (DOS or Windows, or other if he add
- some code) and interprete them in run-time. There are very many applications
- of this tool, like run-time changeable GUI, maketing (without stage of
- compilation, KNOW-HOW.VECTOR is the ready-to-use product of this type) of BGI,
- GDI and so on applications, vector drawing tools. Together with
- BASIC math. functions it could also be used for data plotting, spreadsheets
- and so on.
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ RULES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
-
- 1. 3 types are supported: REAL, STRING and ARRAY (of REAL). Assignment
- could not change the type of variable:
- x = 3
- y = 4
- x = y (OK)
-
- x = "Hello"
- y = x (OK)
-
- x = "Hello"
- y = 3
- y = x (Error)
-
- The array variable must be declared:
- x = 3.5
- MY_ARRAY[12+x];
- Semicolon is necessary to end the declaration. 'x' in this case will be
- rounded down.
- After the initialization array could be used:
- y = MY_ARRAY[12] + 3.21
- Numeration begins from 1 to array dimention, MY_ARRAY[0] contains
- dimention of the array.
- 2. There are the following language constructions:
- a) FOR i = ... TO ...
- ...
- NEXT
- b) !label_name
- ...
- GOTO label_name
- c) IF <condition> THEN ... (othervise go to next line)
- d) Subroutines names should begin from '@':
- @SUB(a, b, "Hi")
- ....
- RETURN (or RETURN REAL or STRING)
- e) Main part of the program should be finished by the END operator.
- f) PLAY("filename") pass the control to the main (END-terminated) routine
- in the external file. Functions of the previous file(s) are not
- available, but variables still are.
- g) There are two types of remarks : & means remark to the end of the line
- and /* * / remarks the whole block.
- h) "Rudimental" Basic functions PRINT and INPUT are still supposed,
- user could use overloaded versions.
- PRINT 5, 7, "Hi"; x, y;
- INPUT "input x: ", x
- ',' is used for listing, ';' begin new line.
- i) PAUSE(msec) suspends the program for given period.
- j) SIN, COS, TAN, ASIN, ACOS, ATAN, ABS, EXP, LOG, LG are the set of
- math. functions of SLANG
- h) DELETE <name> delete variable and release name.
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ FILES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- ▐▐▐▐▐▐▐ File SLANGTAB.H contains language names and messages.
-
- enum { DELIMITER = 1, // '\0'(end),/*,*/,\r,<>=,' ',+-^/*%=;(),<>[]
- VARIABLE, // Symbolic name of variable, like x, k1 and so on
- NUMBER, // Double value
- COMMAND, // See "commands TABLE[]" later in this file
- STRING, // Remarked blocks or quoted text
- QUOTE, // Quote
- ALPHA }; // @ (gosub) or ! (label) symbol
-
-
- enum { IF = 1, THEN, FOR, NEXT, TO, GOTO, EOL, DELETE,
- FINISHED, GOSUB, LABEL, PLAYEX, RETURN, END, REMARK,
- REMARK_BLOCK,
- SIN, COS, TAN, ASIN, ACOS, ATAN, ABS, EXP, LOG, LG,
- PRINT, INPUT, PAUSE,
-
- USER }; // All functions after this are user-defined in Slang childs
-
- struct commands
- {
- char command[20];
- char tok;
- };
-
- static commands TABLE[] = {
- { "if", IF },
- ......................
- #include "userlang.inc"
- { "", END } // Marker of end of the table
- };
-
-
- static char* error_string[] =
- {
- "Syntax error", // 0
- "Symbol '(' or ')' expected", // 1
- ................................................
- "USER ERROR"
- };
-
- Put the special attention to the line
- #include "userlang.inc"
- This trick is used to expand the list of SLANG functions and add user-defined
- ones, which are used by Slang child classes.
- ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- ▐▐▐▐▐▐▐ Files VARIABLE.*, VAR_TAB.* contains descriptions of the variables
- of 3 base types, and the VarTable class - table of variables.
- ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- ▐▐▐▐▐▐▐ Files SLANG.H, SLANG.CPP and BASICA.CPP contains language itself.
- It is recursive interpreter. The most important (for user) functions of
- Slang class:
- void set_error(int err) { error = err; }
- int get_error() { return error; }
- "error" is the number of Slang error (listed in SLANGTAB.H). For
- compatibility I don't use templates, so almost every function should do its
- own error-checking.
- void set_program(char* p) { program = p; }
- char* load_program(char*); // Remove old program and load new file
- "program" is the text loaded from file
- void print(); // General output function
- void input(); // General input function
- PRINT and INPUT are rudimental functions. Some of the Slang childs could
- use another output routines, like outtextxy() and so on.
- void basic(char*); // Executes program pointed by char*
- General routine
- void play(); // Play external file
- virtual void error_report(char* text); // Overload for your own print
- virtual void terminate(); // User-defined terminator (ESC and so on)
- ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«
- -----------------------------------------------------------------------------
- Example.
-
- #include <conio.h> // only for interruption on key pressed **************
- class Demo : public Slang
- {
- virtual void terminate(); // User-defined terminator (ESC and so on)
- };
- /////////////
- void Demo::terminate()
- {
- if(kbhit())
- {
- getch();
- if(kbhit())
- getch();
- serror(23);
- }
- }
- ///////////////////////////////////////////////////////////////////////////
- void main()
- {
- Demo* basic = new Demo();
- basic->basic(basic->load_program("work.bas"));
- delete basic;
- printf("%s", "\n");
- }
-
- Another way of Slang usage - not to call Slang from your program,
- but organize your program as a Slang program, which sometimes could
- include user to dialog using INPUT and other Slang base operations, but
- usually simply call user's functions, including dialog modules, not
- terminating program execution.
-
-
-
-